﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Water.Web.Controls.Office.Excel.Util
{
    public class Report
    {
        /// <summary>
        /// 输出创建Excel对象的VBScript语句
        /// </summary>
        /// <param name="templacePath">Excel模板路径</param>
        /// <returns>创建Excel对象的VBScript语句。
        /// <code>
        /// window.resizeTo 0,0
        /// set Excel = CreateExcelObject("Excel.Application")
        /// Excel.Visible = true
        /// Excel.WorkBooks.Add("http://localhost/demo/Templates/template.xlt")
        /// </code>
        /// </returns>
        public static string CreateExcelObject(string templacePath)
        {
            string _excelObject = "\nwindow.resizeTo 0,0\n"
                + "set Excel = CreateObject(\"Excel.Application\")\n"
                + "Excel.Visible = true\n";

            if (string.IsNullOrEmpty(templacePath))
                _excelObject += "Excel.WorkBooks.Add()\n";
            else
                _excelObject += "Excel.WorkBooks.Add(\"" + templacePath + "\")\n";

            return _excelObject;
        }
        /// <summary>
        /// 输出关闭window的VBScript语句
        /// </summary>
        /// <returns>用VBScript创建window的语句。
        /// <code>
        /// window.close
        /// </code>
        /// </returns>
        public static string WindowColse()
        {
            return "\nwindow.close\n";
        }

    }
}
